<?php
/**
 * @package panel
 * @subpackage panel.environment.loggers
 */
/**
 * Logger to access.log file
 * Log incoming web request to CP.
 * @author Dmitry Bakaleinik (code)
 */
class panel__logger__access
	implements maf__i__singletone {

	/**
	 * @var maf__fso__file
	 */
	protected $file;

	/**
	 * @return panel__logger__access
	 */
	static public function getInstance() {

		static $instance;

		if( !isset($instance) ) {
			$instance = new self; }

		return $instance;

	}	# Function

	protected function __clone() {
	}	# Function

	protected function __sleep() {
	}	# Function

	protected function __wakeup() {
	}	# Function

	protected function __construct() {

		$this->file = new maf__fso__file(PANEL__PATH__LOGS . "/access.log");

	}	# Function

	public function log() {

		$req = array();

		foreach( $_REQUEST as $_key => $_value ) {

			switch( TRUE ) {

			case !is_string($_key):
			case !is_string($_value):
			case $_key == "PHPSESSID":
				continue 2;
				break;

			}	# switch

			$req[] = "{$_key}={$_value}";

		}	# foreach

		$url = sprintf(
			"http://localhost/%s&%s",
			isset_or($_SERVER["REQUEST_URI"],"?"),
			implode("&", $req)
		);

		$this->file->appendContents( $url . "\n" );

	}	# Function

}	# Class

/* EOF */